﻿
Imports System.IO
Imports xmlctrl

Public MustInherit Class controlCounter
    Inherits visitCounter

    Private Class parameters
        <ThreadStatic()> Public Shared key As String = Nothing
        <ThreadStatic()> Public Shared count As Int64 = 0
    End Class

#If RETIRED Then
    Protected MustOverride Overloads Function processInvalidKey(ByVal context As httpContext, ByVal key As String _
                                                                , ByRef control As xmlcontrol) As Boolean
#End If
    Protected MustOverride Overloads Function processHomepage(ByVal context As httpContext _
                                                              , ByRef control As xmlcontrol) As Boolean
    Protected MustOverride Overloads Function processOutput(ByVal context As httpContext, ByVal count As Int64 _
                                                            , ByRef control As xmlcontrol) As Boolean

#If RETIRED Then
    Private Overloads Function processInvalidKey(ByVal context As httpContext, ByRef control As xmlcontrol) As Boolean
        Return processInvalidKey(context, parameters.key, control)
    End Function
#End If

    Private Overloads Function processOutput(ByVal context As httpContext, ByRef control As xmlcontrol) As Boolean
        Return processOutput(context, parameters.count, control)
    End Function

#If RETIRED Then
    Protected Overrides Function processInvalidKey(ByVal context As httpContext, ByVal key As String) As Boolean
        copy(parameters.key, key)
        Return controlProcessor.process2(context, AddressOf processInvalidKey, False)
    End Function
#End If

    Protected Overrides Function processHomepage(ByVal context As httpContext) As Boolean
        Return controlProcessor.process2(context, AddressOf processHomepage, False)
    End Function

    Protected Overrides Function processOutput(ByVal context As httpContext, ByVal count As Int64) As Boolean
        copy(parameters.count, count)
        Return controlProcessor.process2(context, AddressOf processOutput, False)
        'base class counter can set cache control
    End Function
End Class
